class Solution:
    def maxProfit(self, prices):
        """
        :type prices: List[int]
        :rtype: int
        """

        n = len(prices)
        if n == 0:
            return 0

        b = prices[0]
        a = 0
        for i in range(1, n):
            b = min(b, prices[i])
            a = max(a, prices[i] - b)
        return a
